import {SysNewsData, SysNewsAdd} from "@/pages/news/type";
import {ReactNode} from "react";
import {UseFetchDataAction} from "@ant-design/pro-table/es/typing";
import {Button, Space} from "antd";
import {ProColumns} from "@ant-design/pro-table";
import {OptionActions} from "@/type/type";
import AddSysNews from "@/pages/news/list/components/AddSysNews";
import AuthWrapper from "@/components/AuthWrapper";

// @ts-ignore
const columns: ProColumns<SysNewsData> = (optionAction: OptionActions<SysNewsAdd, SysNewsData>) => {
  return [
    {
      dataIndex: "index",
      valueType: "index",
    },
    {
      title: "标题",
      dataIndex: "title",
      align: 'center',
    },
    {
      title: "分类id",
      dataIndex: "category",
      align: 'center',
    },
    {
      title: "内容",
      dataIndex: "content",
      align: 'center',
    },
    {
      title: "状态",
      dataIndex: "status",
      align: 'center',

    },
    {
      title: "操作",
      valueType: 'option',
      align: "center",
      key: "option",
      width: "200px",
      render: (text: ReactNode, record: SysNewsData, index: number, action: UseFetchDataAction<SysNewsData>) => {
        return (
          <Space>
            <AuthWrapper authorize={":edit"}>
              {(authorized: boolean) => <AddSysNews initialValues={record}
                                                    disabled={!authorized} {...optionAction.editModal(record, authorized)}/>}
            </AuthWrapper>
            <AuthWrapper authorize={":remove"}>
              {(authorized: boolean) => <Button type="link" disabled={!authorized} danger onClick={() =>
                optionAction.remove([record.id])}>删除</Button>}
            </AuthWrapper>
          </Space>
        )
      }
    }
  ]


}


export default columns;
